package org.loofer.baseframe;

import java.util.ArrayList;
import java.util.List;

import android.view.View;
import android.widget.Toast;
import com.example.okhttp.OKHttpFactory.OKHttpPresenter;
import com.example.okhttp.OKHttpFactory.OKHttpView;
import com.example.okhttp.utils.BaseMVPActivity;
import com.example.okhttp.utils.BaseRecycleView;
import com.example.okhttp.utils.FinalRecycleView;


/**
 * Created by Seeker on 2016/7/28.
 */

public class OKHttpMangerActivity extends BaseMVPActivity
        <OKHttpView<Result>,OKHttpPresenter> implements OKHttpView<Result>,BaseRecycleView.OnItemClickListener{


    private List<Info> infos = new ArrayList<Info>();

    FinalRecycleView finalRecycleView;

    View emptyView;

    private OKHttpAdapter myAdapter;

    @Override
    public void onbind() {
        super.onbind();
        finalRecycleView = (FinalRecycleView) findViewById(R.id.finalRecycleView);
        emptyView = findViewById(R.id.emptyView);
        
        findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				 presenter.load();
			}
		});
        
    }

    @Override
    public void unbind() {
        super.unbind();
    }

    @Override
    public void onPreLoad() {
        Toast.makeText(this,"加载数据",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFinishLoad() {
        Toast.makeText(this,"加载完成",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void loadError() {
        Toast.makeText(this,"加载有误",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void setDatas(Result datas) {
        infos.addAll(datas.getData());
        myAdapter.notifyDataSetChanged();
    }

    @Override
    public OKHttpFactory.OKHttpPresenter initPresenter() {
        return new OKHttpFactory.OKHttpPresenter();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_recycleview;
    }

    @Override
    public void doWork() {
        myAdapter = new OKHttpAdapter(this,infos);
        finalRecycleView.setAdapter(myAdapter);
        finalRecycleView.setEmptyView(emptyView);
        finalRecycleView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(View itemView, int position) {
        new ProgressBarDialog(this,infos.get(position).getPicBig()).show();
    }
}
